﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class GeneralMiscTypeManager
    {
        public static IEnumerable<GeneralMiscType> GetGeneralMiscTypes()
        {
            IEnumerable<GeneralMiscType> generalMiscTypes;
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                generalMiscTypes = unitOfWork.GeneralMiscTypeRepository.GetAll();
            }
            return generalMiscTypes;
        }

        public static bool AddGeneralMiscType(GeneralMiscType generalMiscType)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                unitOfWork.GeneralMiscTypeRepository.Add(generalMiscType);
                unitOfWork.Save();
            }
            return true;
        }

        // public bool UpdateGeneralMiscType(GeneralMiscType generalMiscType, int id)
        // {
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // var generalMiscTypeEntity = unitOfWork.GeneralMiscTypeRepository.GetById(id);
        // generalMiscTypeEntity.Title = generalMiscType.Title;
        // generalMiscTypeEntity.FirstName = generalMiscType.FirstName;
        // generalMiscTypeEntity.LastName = generalMiscType.LastName;
        // generalMiscTypeEntity.ModifiedDate = DateTime.Now;
        // unitOfWork.Save();
        // }
        // return true;
        // }
         public static bool UpdateGeneralMiscType(GeneralMiscType generalMiscType)
         {
             using (UnitOfWork unitOfWork= new UnitOfWork())
             {
                 unitOfWork.GeneralMiscTypeRepository.Update(generalMiscType);
                 unitOfWork.Save();
             }
             return true;
         }

    public static bool DeleteGeneralMiscType(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                GeneralMiscType generalMiscType=unitOfWork.GeneralMiscTypeRepository.GetById(id);
                //unitOfWork.GeneralMiscTypeRepository.Delete(generalMiscType);
                generalMiscType.Deleted = true;
                generalMiscType.DeletedDate = DateTime.Now;
                unitOfWork.Save();
            }
            return true;
        }

        // public List<GeneralMiscType> GetGeneralMiscTypePaged(int page, int rows, out int totalCount)
        // {
        // List<GeneralMiscType> generalMiscTypes;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // generalMiscTypes = unitOfWork.GeneralMiscTypeRepository.GetGeneralMiscTypePaged
        // (page, rows, out totalCount);
        // }
        // return generalMiscTypes;
        // }
        public static GeneralMiscType GetById(int id) {
            GeneralMiscType generalMiscType;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                generalMiscType=unitOfWork.GeneralMiscTypeRepository.GetById(id);
            }
            return generalMiscType;
        }

        public static IEnumerable<GeneralMiscType> GetParents()
        {
            IEnumerable<GeneralMiscType> generalMiscTypes;
            using(UnitOfWork unitOfWork=new UnitOfWork())
            {
                generalMiscTypes =
                    unitOfWork.GeneralMiscTypeRepository.GetMany(x => x.Deleted == false && x.ParentID == 0);
            }
            return generalMiscTypes;
        }

        public static IEnumerable<GeneralMiscType> GetChildren(int parentId) {
            IEnumerable<GeneralMiscType> generalMiscTypes;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                generalMiscTypes=
                    unitOfWork.GeneralMiscTypeRepository.GetMany(x => x.Deleted==false&&x.ParentID==parentId);
            }
            return generalMiscTypes;
        }

    }
}
